package main

func removeDuplicateNodes(head *ListNode) *ListNode {
	if head == nil {
		return head
	}
	m := make(map[int]struct{})

	temp := head

	m[temp.Val] = struct{}{}
	for temp.Next != nil {
		value := temp.Next.Val
		_, ok := m[value]
		if ok {
			temp.Next = temp.Next.Next
			continue
		} else {
			m[value] = struct{}{}
		}

		temp = temp.Next
	}

	return head
}
